/**
* @program: src
*
* @description:
*
* @author: Mr.chen
*
* @create: 2022-04-11 14:57
**/
package logic

import (
	"context"
	pb "do_demo/srv/proto/logic"
	"google.golang.org/grpc"
	"time"
)

var (
	// grpc options
	grpcKeepAliveTime    = time.Duration(10) * time.Second
	grpcKeepAliveTimeout = time.Duration(3) * time.Second
	grpcBackoffMaxDelay  = time.Duration(3) * time.Second
	grpcMaxSendMsgSize   = 1 << 24
	grpcMaxCallMsgSize   = 1 << 24
)

const (
	// grpc options
	grpcInitialWindowSize     = 1 << 24
	grpcInitialConnWindowSize = 1 << 24
)
type (
	TestSrvReq     = pb.TestSrvReq
	TestSrvReply    = pb.TestSrvReply
	ILogicClient interface {
		TestSrv(ctx context.Context, in *TestSrvReq, opts ...grpc.CallOption) (*TestSrvReply, error)
	}
	// logic
	LogicClient struct {
		cli    *grpc.ClientConn
		ctx    context.Context
		cancel context.CancelFunc
	}
)

// 初始化Logic客户端，当前客户端是一开始定好的，每次都需要设置新的客户端，使用grpc.resolver
func NewLogicClient(cli *grpc.ClientConn) ILogicClient {
	logicClient := &LogicClient{}
	logicClient.cli = cli
	logicClient.ctx, logicClient.cancel = context.WithCancel(context.Background())
	return logicClient
}

//  当前这步需要分离可以另外起服务，为了测试暂时先放这里
func (l *LogicClient) TestSrv(ctx context.Context, in *TestSrvReq, opts ...grpc.CallOption) (*TestSrvReply, error){
	client := pb.NewLogicClient(l.cli)
	return client.TestSrv(ctx, in, opts...)
}